package com.apexbrain.apexbrainserver.mapper;

import com.apexbrain.apexbrainserver.pojo.Question;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * 问题表tb_question的mapper
 */
@Mapper
public interface QuestionMapper
{
    /**
     * 获取问题数量
     * @return 问题表中问题的数量
     */
    @Select("select count(*) from tb_question;")
    int getQuestionCount();

    /**
     * 获取问题及其答案
     * @param questionId 问题id
     * @return 返回问题pojo对象
     */
    @Select("select " +
                "question_id, " +
                "info, " +
                "question, " +
                "correct_answer, " +
                "wrong_answer0, " +
                "wrong_answer1, " +
                "wrong_answer2 " +
            "from " +
                "tb_question " +
            "join " +
                "tb_question_category " +
            "on " +
                "tb_question.category_id = tb_question_category.category_id " +
            "where question_id = ${questionId}")
    @Results(id = "question_result_map_id", value = {
            @Result(id = true, column = "question_id", property = "questionId"),
            @Result(column = "info", property = "category"),
            @Result(column = "correct_answer", property = "correctAnswer"),
            @Result(column = "wrong_answer0", property = "wrongAnswer0"),
            @Result(column = "wrong_answer1", property = "wrongAnswer1"),
            @Result(column = "wrong_answer2", property = "wrongAnswer2")
    })
    Question getQuestion(int questionId);
}
